//
//  MyCell.m
//  SelectionForYou
//
//  Created by qianfeng on 15-6-8.
//  Copyright (c) 2015年 朱共营. All rights reserved.
//

#import "MyCell.h"
#import "UIImageView+WebCache.h"
#import "LZXHelper.h"
@implementation MyCell

- (void)awakeFromNib {
    self.headline_img_tbImage.layer.masksToBounds=YES;
    self.headline_img_tbImage.layer.cornerRadius=6;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    
        UIView *line=self.blackView;
        line.backgroundColor=[UIColor blackColor];
     //   NSLog(@"aa123");
  
    [self reloadInputViews];
    
}
- (void)showDataWithModel:(MyModel *)model{
    [self.headline_img_tbImage sd_setImageWithURL:[NSURL URLWithString:model.headline_img] placeholderImage: [UIImage imageNamed: @"load.jpg" ] ];
    self.titleLable.text=model.title;
    self.source_nameLable.text=model.source_name;
 //   NSString *dateTime=[LZXHelper dateStringFromNumberTimer:model.date_picked];
    
  //  NSLog(@"%@",dateTime);
 //   NSString *dateTime2=[LZXHelper dateStringFromNumberTimer:model.date_created];
  //  NSLog(@"%@",dateTime2);
    /*
    //NSLog(@"%@",dateTime-dateTime2);
//    self.date_pickeLable.text=[NSString stringWithFormat:@"%@ ",[LZXHelper stringNowToDate:dateTime formater:@"yyyy-MM-dd HH:mm:ss"]];
    NSLog(@"%@",[LZXHelper stringNowToDate:dateTime formater:@"yyyy-MM-dd HH:mm:ss"]);
   
    
    NSDate *date=[NSDate date];
    
    NSLog(@"date:%@",date);
    NSTimeZone *timerZone=[NSTimeZone systemTimeZone];
      NSLog(@"TimeZone:%@",timerZone);
    NSTimeInterval sub=[timerZone secondsFromGMTForDate:date];
      NSLog(@"Sub:%f",sub);
    NSDate *locationTime=[NSDate dateWithTimeInterval:sub sinceDate:date];
      NSLog(@"locationTime:%@",locationTime);
    self.date_pickeLable.text=(NSString *)locationTime;
    NSLog(@"%@",self.date_pickeLable.text);
    
 //NSLog(@"%@", [self getUTCFormateDate:[LZXHelper stringNowToDate:[NSString stringWithFormat:model.date_created] formater:@"yyyy-MM-dd HH:mm:ss"]])  ;
   */
     
     self.date_pickeLable.text=[self getUTCFormateDate:model.date_picked];
    
   // NSLog(@"%@",[self getUTCFormateDate:model.date_created]);
    
    
    
   
}
- (NSString *)getUTCFormateDate:(NSString *)newData{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
  //  NSLog(@"newsDate = %@",newData);
    
    NSString *dateTime=[LZXHelper dateStringFromNumberTimer:newData];
    
    NSDate *newsDateFormatted = [dateFormatter dateFromString:dateTime];
    NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
    [dateFormatter setTimeZone:timeZone];
    
    NSDate* current_date = [[NSDate alloc] init];
    
    NSTimeInterval time=[current_date timeIntervalSinceDate:newsDateFormatted];//间隔的秒数
    int month=((int)time)/(3600*24*30);
    int days=((int)time)/(3600*24);
    int hours=((int)time)%(3600*24)/3600;
    int minute=((int)time)%(3600*24)/60;
  //  NSLog(@"time=%f",(double)time);
    
    NSString *dateContent;
    
    if(month!=0){
        
        dateContent = [NSString stringWithFormat:@"%@%i%@",@"   ",month,@"个月前"];
        
    }else if(days!=0){
        
        dateContent = [NSString stringWithFormat:@"%@%i%@",@"   ",days,@"天前"];
    }else if(hours!=0){
        
        dateContent = [NSString stringWithFormat:@"%@%i%@",@"   ",hours,@"小时前"];
    }else {
        
        dateContent = [NSString stringWithFormat:@"%@%i%@",@"   ",minute,@"分钟前"];
    }
    
    //    NSString *dateContent=[[NSString alloc] initWithFormat:@"%i天%i小时",days,hours];
    
    
    return dateContent;

}
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    [super setSelected:highlighted animated:animated];
    UIView *line=self.blackView;
    line.backgroundColor=[UIColor grayColor];
   //  NSLog(@"hahah123");
    [self reloadInputViews];
}

@end
